<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The PriorityQueue class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ds-queue.toarray.html">« Ds\Queue::toArray</a></li>
      <li style="float: right;"><a href="ds-priorityqueue.allocate.html">Ds\PriorityQueue::allocate »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.ds.html">Data Structures</a></li>
    <li>The PriorityQueue class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.ds-priorityqueue" class="reference">

 <h1 class="title">The PriorityQueue class</h1>
 

 <div class="partintro"><p class="verinfo">(No version information available, might only be in Git)</p>


  <div class="section" id="ds-priorityqueue.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    A PriorityQueue is very similar to a Queue. Values are pushed into the queue
    with an assigned priority, and the value with the highest priority will
    always be at the front of the queue.
   </p>
   <p class="para">
        Implemented using a max heap.
   </p>
   <blockquote class="note"><p><strong class="note">注意</strong>: 
        <p class="para">
            &quot;First in, first out&quot; ordering is preserved for values with the same priority.
        </p>
   </p></blockquote>
   <blockquote class="note"><p><strong class="note">注意</strong>: 
        <p class="para">
            Iterating over a PriorityQueue is destructive, equivalent to successive pop operations until the queue is empty.
        </p>
   </p></blockquote>
  </div>


  <div class="section" id="ds-priorityqueue.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">Ds\PriorityQueue</strong>
     </span>

     <span class="oointerface"><span class="modifier">implements</span> 
       <strong class="interfacename">Ds\Collection</strong></span> {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.ds-priorityqueue.html#ds-priorityqueue.constants.min-capacity"><var class="varname">MIN_CAPACITY</var></a></var><span class="initializer"> = 8</span>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="ds-priorityqueue.allocate.html" class="methodname">allocate</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$capacity</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-priorityqueue.capacity.html" class="methodname">capacity</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-priorityqueue.clear.html" class="methodname">clear</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-priorityqueue.copy.html" class="methodname">copy</a></span>(): <span class="type"><a href="class.ds-priorityqueue.html" class="type Ds\PriorityQueue">Ds\PriorityQueue</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-priorityqueue.isempty.html" class="methodname">isEmpty</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-priorityqueue.peek.html" class="methodname">peek</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-priorityqueue.pop.html" class="methodname">pop</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-priorityqueue.push.html" class="methodname">push</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$priority</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-priorityqueue.toarray.html" class="methodname">toArray</a></span>(): <span class="type">array</span></div>

   }</div>


  </div>


  <div class="section" id="ds-priorityqueue.constants">
   <h2 class="title">预定义常量</h2>
   <dl>

    
     <dt id="ds-priorityqueue.constants.min-capacity"><strong><code>Ds\PriorityQueue::MIN_CAPACITY</code></strong></dt>

     <dd>

      <p class="para"/>
     </dd>

    

   </dl>

  </div>



 </div>

 





















































































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="ds-priorityqueue.allocate.html">Ds\PriorityQueue::allocate</a> — Allocates enough memory for a required capacity</li><li><a href="ds-priorityqueue.capacity.html">Ds\PriorityQueue::capacity</a> — Returns the current capacity</li><li><a href="ds-priorityqueue.clear.html">Ds\PriorityQueue::clear</a> — Removes all values</li><li><a href="ds-priorityqueue.construct.html">Ds\PriorityQueue::__construct</a> — Creates a new instance</li><li><a href="ds-priorityqueue.copy.html">Ds\PriorityQueue::copy</a> — Returns a shallow copy of the queue</li><li><a href="ds-priorityqueue.count.html">Ds\PriorityQueue::count</a> — Returns the number of values in the queue</li><li><a href="ds-priorityqueue.isempty.html">Ds\PriorityQueue::isEmpty</a> — Returns whether the queue is empty</li><li><a href="ds-priorityqueue.jsonserialize.html">Ds\PriorityQueue::jsonSerialize</a> — Returns a representation that can be converted to JSON</li><li><a href="ds-priorityqueue.peek.html">Ds\PriorityQueue::peek</a> — Returns the value at the front of the queue</li><li><a href="ds-priorityqueue.pop.html">Ds\PriorityQueue::pop</a> — Removes and returns the value with the highest priority</li><li><a href="ds-priorityqueue.push.html">Ds\PriorityQueue::push</a> — Pushes values into the queue</li><li><a href="ds-priorityqueue.toarray.html">Ds\PriorityQueue::toArray</a> — Converts the queue to an array</li></ul>
</div>
</div></div></body></html>